package com.anlogic.sdk.tools.utils;

import com.anlogic.sdk.tools.IBspTool;
import com.anlogic.sdk.tools.exetool.ExeBspTool;
import com.anlogic.sdk.tools.nativetool.JniBspTool;
import com.anlogic.sdk.utils.EnvUtils;
import com.anlogic.sdk.utils.options.ChipType;

public class ToolsUtils {
	public static final String EXEBSPTOOL = "ExeBspTool";
	public static final String JNIBSPTOOL = "JniBspTool";

	public static int getBspToolTimeout() {
		String timeout = System.getProperty("com.anlogic.sdk.tools.bspToolTimeout", "5000");
		if (timeout != null && timeout.length() > 0) {
			try {
				return Integer.parseInt(timeout);
			} catch (Exception e) {
				return 5000;
			}
		}
		return 5000;
	}
	
	public static IBspTool getBspTool() {
		IBspTool bspTool = ExeBspTool.getInstance();
		String bspToolType = System.getProperty("com.anlogic.sdk.tools.bspToolType", "ExeBspTool");
		if (bspToolType.equals(JNIBSPTOOL)) {
			bspTool = new JniBspTool();
		}
		return bspTool;
	}
	
	public static IBspTool getBspTool(String chip) {
		IBspTool bspTool = ExeBspTool.getInstance();
		bspTool.setChip(chip);
		String bspToolType = System.getProperty("com.anlogic.sdk.tools.bspToolType", "ExeBspTool");
		if (bspToolType.equals(JNIBSPTOOL)) {
			bspTool = new JniBspTool(chip);
		}
		return bspTool;
	}
	
	public static String getBspResourcePath(String chip) {
		String srcPath = "";
		if (ChipType.isDr1(chip)) {
			srcPath = String.format("%s/dr1x90", EnvUtils.getBspResourcePath());
		} else {
			srcPath = String.format("%s/%s", EnvUtils.getBspResourcePath(), chip);
		}
		return srcPath;
	}
	
	public static String getConfigFilePath(String chip) {
		String cfgFile = "";
		cfgFile = String.format("%s/docs/depend.json", getBspResourcePath(chip));
		return cfgFile;
	}
}
